#include <iostream>
#include <vector>
using namespace std;
 
int main()
{
    int n = 0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    vector<int> dp(n);
    int res = a[0];
    dp[0] = a[0];
    for(int i = 1; i < n; ++i)
    {
        dp[i] = max(dp[i - 1] + a[i], a[i]);
        res = max(res, dp[i]);
    }
    cout << res << endl;
    return 0;
}